package artid.com.arttogo.adapter;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.QrHisItem;
import artid.com.arttogo.db.WhiteListDb;


public class DeleteAdapter extends BaseAdapter {

	private ArrayList<QrHisItem> listDatas = new ArrayList<QrHisItem>();
	private LayoutInflater mInflater;
	private Context context;
	private WhiteListDb db;
	private SQLiteDatabase sd;
	private Handler handler;
	public DeleteAdapter(Context context, ArrayList<QrHisItem> arrayList) {
		mInflater = LayoutInflater.from(context);

		listDatas.clear();	
		listDatas.addAll(arrayList);
		this.context = context;
	}

	@Override
	public int getCount() {
		return listDatas == null ? 0 : listDatas.size();
	}

	@Override
	public Object getItem(int position) {
		return listDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void setListData(ArrayList<QrHisItem> arrayList){
	
		listDatas = arrayList;
		notifyDataSetChanged();
	}
	@Override
	public View getView(int posi, View convertView, ViewGroup parent) {
		final int position = posi;
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_scan_history, null);
			holder.name = (TextView)convertView.findViewById(R.id.item_scan_his_title);
			holder.artist = (TextView)convertView.findViewById(R.id.item_scan_his_artist);
			holder.time = (TextView)convertView.findViewById(R.id.item_scan_his_time);
//			holder.itemData = (TextView) convertView
//					.findViewById(R.id.itemdata);
//			holder.itemurl = (TextView) convertView
//					.findViewById(R.id.itemurl);
//			holder.itemdate = (TextView) convertView
//					.findViewById(R.id.itemDate);
//			
//			holder.itemChapter = (TextView) convertView
//					.findViewById(R.id.itemchapter);
//			holder.coating = (TextView) convertView.findViewById(R.id.tv_coating);
//			holder.functions = (TextView) convertView.findViewById(R.id.tv_functions);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String resourceTitle = listDatas.get(position).getTitle();
		if(!TextUtils.isEmpty(resourceTitle)){
			holder.name.setText(resourceTitle);
		}else{
			holder.name.setText("名称");
		}

		holder.artist.setText(listDatas.get(position).getAuther());
		holder.time.setText(listDatas.get(position).getTime());
//		holder.coating.setVisibility(View.VISIBLE);
		//holder.functions.setClickable(false);

		return convertView;
	}

	class ViewHolder {
		TextView name,artist,time;
		Button btnDelete;
	}

	private Toast mToast;

	public void showInfo(String text) {
		if (mToast == null) {
			mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
		} else {
			mToast.setText(text);
			mToast.setDuration(Toast.LENGTH_SHORT);
		}
		mToast.show();
	}

	
}
